        </main>
        <!-- 主要内容区域结束 -->
    </div>

    <!-- 页脚脚本 -->
    <script>
        // 通用JavaScript功能

        // 确认删除对话框
        function confirmDelete(message = '确定要删除这些项目吗？') {
            return confirm(message);
        }

        // 全选/取消全选功能
        function toggleSelectAll(selectAllCheckbox) {
            const checkboxes = document.querySelectorAll('input[type="checkbox"][name*="[]"]');
            checkboxes.forEach(checkbox => {
                if (checkbox !== selectAllCheckbox) {
                    checkbox.checked = selectAllCheckbox.checked;
                }
            });
        }

        // 检查是否有选中项
        function hasSelectedItems(checkboxName) {
            const checkboxes = document.querySelectorAll(`input[name="${checkboxName}"]:checked`);
            return checkboxes.length > 0;
        }

        // 表单提交前验证
        function validateForm(formId, requiredFields = []) {
            const form = document.getElementById(formId);
            if (!form) return true;

            for (let fieldName of requiredFields) {
                const field = form.querySelector(`[name="${fieldName}"]`);
                if (field && !field.value.trim()) {
                    alert(`请填写${field.getAttribute('data-label') || fieldName}`);
                    field.focus();
                    return false;
                }
            }
            return true;
        }

        // 自动隐藏消息提示
        document.addEventListener('DOMContentLoaded', function() {
            const alerts = document.querySelectorAll('.alert');
            alerts.forEach(alert => {
                setTimeout(() => {
                    alert.style.opacity = '0';
                    setTimeout(() => {
                        alert.remove();
                    }, 300);
                }, 5000);
            });
        });

        // 表格排序功能
        function sortTable(columnIndex, order = 'asc') {
            const urlParams = new URLSearchParams(window.location.search);
            urlParams.set('sort_column', columnIndex);
            urlParams.set('sort_order', order);
            window.location.search = urlParams.toString();
        }

        // 搜索功能
        function performSearch(searchTerm, searchField = '') {
            const urlParams = new URLSearchParams(window.location.search);
            if (searchTerm.trim()) {
                urlParams.set('search', searchTerm);
                if (searchField) {
                    urlParams.set('search_field', searchField);
                }
            } else {
                urlParams.delete('search');
                urlParams.delete('search_field');
            }
            urlParams.delete('page'); // 重置到第一页
            window.location.search = urlParams.toString();
        }

        // 分页功能
        function goToPage(page) {
            const urlParams = new URLSearchParams(window.location.search);
            urlParams.set('page', page);
            window.location.search = urlParams.toString();
        }

        // 批量操作确认
        function confirmBatchAction(action, checkboxName) {
            if (!hasSelectedItems(checkboxName)) {
                alert('请至少选择一项');
                return false;
            }

            const selectedCount = document.querySelectorAll(`input[name="${checkboxName}"]:checked`).length;
            return confirm(`确定要对选中的 ${selectedCount} 项执行"${action}"操作吗？`);
        }

        // 实时搜索（防抖）
        let searchTimeout;
        function debounceSearch(searchInput, delay = 500) {
            clearTimeout(searchTimeout);
            searchTimeout = setTimeout(() => {
                performSearch(searchInput.value);
            }, delay);
        }

        // 表格行点击选中
        function setupRowSelection() {
            const tableRows = document.querySelectorAll('.data-table tbody tr');
            tableRows.forEach(row => {
                row.addEventListener('click', function(e) {
                    if (e.target.type !== 'checkbox' && e.target.tagName !== 'A' && e.target.tagName !== 'BUTTON') {
                        const checkbox = this.querySelector('input[type="checkbox"]');
                        if (checkbox) {
                            checkbox.checked = !checkbox.checked;
                            this.classList.toggle('selected', checkbox.checked);
                        }
                    }
                });
            });
        }

        // 页面加载完成后初始化
        document.addEventListener('DOMContentLoaded', function() {
            setupRowSelection();

            // 为搜索框添加实时搜索
            const searchInputs = document.querySelectorAll('.search-input');
            searchInputs.forEach(input => {
                input.addEventListener('input', function() {
                    debounceSearch(this);
                });
            });

            // 为全选框添加事件监听
            const selectAllCheckbox = document.querySelector('#select-all');
            if (selectAllCheckbox) {
                selectAllCheckbox.addEventListener('change', function() {
                    toggleSelectAll(this);
                });
            }
        });
    </script>
</body>
</html>